package com.example.hm_dtfkz.ui.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.WindowManager;

import com.android.base.util.ActivityClickUtil;
import com.android.base.util.DQLog;
import com.android.base.util.DisplayUtil;
import com.android.base.util.SystemUtil;
import com.android.base.util.ToastUtil;
import com.example.hm_dtfkz.R;
import com.example.hm_dtfkz.databinding.DialogJointQqBinding;

public class DialogJointQQ extends Dialog {

    private DialogJointQqBinding jointQQBinding;
    private final Activity activity;

    public DialogJointQQ(Activity a) {
        super(a, R.style.dialog_loading);
        this.activity = a;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        jointQQBinding = DialogJointQqBinding.inflate(getLayoutInflater());
        setContentView(jointQQBinding.getRoot());

        getWindow().getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.width = DisplayUtil.getScreenWidth(activity);
        lp.height = DisplayUtil.getScreenHeight(activity);
        getWindow().setAttributes(lp);

        setCanceledOnTouchOutside(false);
        setCancelable(false);
        initView();
    }

    private void initView() {
        ActivityClickUtil.getInstance().clear();

        jointQQBinding.imgReceive.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (ActivityClickUtil.getInstance().isFastClick()) {
                    //防止用户快速点击
                    return;
                }

                String qq = jointQQBinding.edQQ.getText().toString().trim();
                if (TextUtils.isEmpty(qq)) {
                    ToastUtil.showShortToast(activity, "QQ号不能为空");
                    return;
                }

                if (qq.length() < 5) {
                    ToastUtil.showShortToast(activity, "QQ号错误，请重新输入");
                    return;
                }

//                HXCurrencySDK.getInstance().bind(4, "", "", qq, 0, new HttpUtil.HttpUtilCallback() {
//                    @Override
//                    public void onSuccess(int reqCode, String response) {
//                        DQLog.e("绑定QQ成功：" + response);
//                        BindResp bindResp = JsonUtil.parseObject(response, BindResp.class);
//                        if (bindResp != null) {
//                            int errorCode = bindResp.getErrorCode();
//                            String errorMessage = bindResp.getErrorMessage();
//                            if (errorCode == 0) {
//                                AppConfig.hasQQ = 1;
//                                ToastUtil.showShortToast(activity, "绑定QQ成功");
//                                SystemUtil.joinQQGroup(activity, AppConfig.QQ_GROUP_KEY);
//                                dismiss();
//                            } else {
//                                ToastUtil.showShortToast(activity, errorMessage);
//                            }
//                        } else {
//                            ToastUtil.showShortToast(activity, "绑定QQ失败");
//                        }
//                    }
//
//                    @Override
//                    public void onFailed(int reqCode, Throwable throwable) {
//                        DQLog.e("绑定微信失败：" + throwable.getMessage());
//                        ToastUtil.showShortToast(activity, "绑定QQ失败：" + throwable.getMessage());
//                    }
//                });
            }
        });
        jointQQBinding.imgClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (ActivityClickUtil.getInstance().isFastClick()) {
                    //防止用户快速点击
                    return;
                }
                dismiss();
            }
        });

    }
}
